package com.san.oms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.san.base.domain.Tree;
import com.san.common.utils.BuildTree;
import com.san.oms.dao.QuotaDao;
import com.san.oms.domain.QuotaDO;
import com.san.oms.service.QuotaService;

/**
 * 监测模型服务实现
 * 
 * @author Administrator
 *
 */
@Service
public class QuotaServiceImpl implements QuotaService {

	@Autowired
	private QuotaDao dao;

	@Override
	public List<QuotaDO> getQuotaList(Long modelId) throws Exception {
		return dao.getQuotaList(modelId);
	}

	@Override
	public Object getById(Long quotaId) throws Exception {
		return dao.getById(quotaId);
	}

	@Override
	public int save(Object o) throws Exception {
		return dao.save(o);
	}

	@Override
	public int doEdit(Object o) throws Exception {
		return dao.doEdit(o);
	}

	@Override
	public int remove(Long id) throws Exception {
		return dao.remove(id);
	}

	@Override
	public List<QuotaDO> findQuotaList(Map<String, Object> condition) throws Exception {
		return dao.findQuotaList(condition);
	}

	@Override
	public List<QuotaDO> findSubset(Long modelId, Long parentId) throws Exception {
		return dao.findSubset(modelId, parentId);
	}

	@Override
	public Tree<QuotaDO> getQuotaTree() throws Exception {
		List<Tree<QuotaDO>> trees = new ArrayList<Tree<QuotaDO>>();

		List<QuotaDO> list = dao.findQuotaList(null);
		for (QuotaDO quota : list) {
			Tree<QuotaDO> tree = new Tree<QuotaDO>();
			tree.setId(quota.getQuotaId().toString());
			tree.setParentId(quota.getParentId().toString());
			tree.setText(quota.getQuotaName());
			Map<String, Object> state = new HashMap<>(16);
			state.put("opened", true);
			state.put("mType", "dept");
			tree.setState(state);
			trees.add(tree);
		}
		return BuildTree.build(trees, true);
	}

	@Override
	public int batchRemove(Long[] ids) throws Exception {
		return dao.batchRemove(ids);
	}

}
